/*
 * @Date: 2020-11-24 21:28:39
 * @LastEditors: 小枫
 * @description: description
 * @LastEditTime: 2020-11-27 18:17:40
 * @FilePath: \stu-nest\src\app.module.ts
 */
import { MiddlewareConsumer, Module, RequestMethod } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { HelloModule } from './modules/hello/hello.module';
import { LoggerMiddleware } from './common/middleware/logger.middleware';
import { EmailModule } from './modules/email/email.module';
import { MailerModule } from '@nestjs-modules/mailer';
import { ConfigModule, ConfigService } from 'nestjs-config';
import { resolve } from 'path';
import { StatusMonitorModule } from 'nest-status-monitor';
import statusMonitorConfig from './config/status';
import { AuthModule } from './modules/auth/auth.module';
import { TypeOrmModule } from '@nestjs/typeorm';

@Module({
  imports: [
    ConfigModule.load(resolve(__dirname, 'config', '**/!(*.d).{ts,js}')),
    TypeOrmModule.forRootAsync({
      useFactory: (config: ConfigService) => config.get('database'),
      inject: [ConfigService],
    }),
    StatusMonitorModule.setUp(statusMonitorConfig),
    MailerModule.forRootAsync({
      // useFactory: () => ({
      //   transport: 'smtps://1984779164@qq.com:qwwsvgcvmjuedhbj@smtp.qq.com',
      //   defaults: {
      //     from: '"nest-modules" <modules@nestjs.com>',
      //   },
      //   template: {
      //     dir: path.join(__dirname, './template/email'),
      //     adapter: new PugAdapter(),
      //     options: {
      //       strict: true,
      //     },
      //   },
      // }),
      useFactory: (config: ConfigService) => config.get('email'),
      inject: [ConfigService],
    }),
    HelloModule,
    EmailModule,
    AuthModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(LoggerMiddleware)
      .exclude({ path: 'hello', method: RequestMethod.POST })
      .forRoutes('hello');
  }
}
